﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Catering.yl.Daily
{
    public partial class EMaintenance : System.Web.UI.Page
    {
        static string classId = "";
        static string zyqbh = "";
        static string bzbh = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            classId = Session["ClassID"].ToString();
            BaoXiuDate.Text = DateTime.Today.ToShortDateString();
            StartRepairDate.Text = DateTime.Today.ToShortDateString();
            EndRepairDate.Text = DateTime.Today.ToShortDateString(); 
        }

        protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
        {
            if( CheckBox1.Checked )            
                CheckBox2.Checked = false;            
            else
                CheckBox2.Checked = true;
        }

        protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
        {
            if (CheckBox2.Checked)
                CheckBox1.Checked = false;
            else
                CheckBox1.Checked = true;
        }

        protected void CheckBox3_CheckedChanged(object sender, EventArgs e)
        {
            if (CheckBox3.Checked)
            {
                CheckBox4.Checked = false;
                CheckBox5.Checked = false;     
            }                       
        }

        protected void CheckBox4_CheckedChanged(object sender, EventArgs e)
        {
            if (CheckBox4.Checked)
            {
                CheckBox3.Checked = false;
                CheckBox5.Checked = false;
            }  
        }

        protected void CheckBox5_CheckedChanged(object sender, EventArgs e)
        {
            if (CheckBox5.Checked)
            {
                CheckBox4.Checked = false;
                CheckBox3.Checked = false;
            }  
        }

        protected void Save_Click(object sender, EventArgs e)
        {
            if( RepairingDesc.Text == "")
            {
                ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "onekey", "alert('维修保养过程简述不能为空！')", true);
                return;
            }
                
            Catering_Model.EMaintenance _EM = new Catering_Model.EMaintenance();
            _EM.DailyManagementID = int.Parse("10");
            _EM.GroupID = "";
            _EM.ClassID = classId;
            _EM.SafeHiddenTroubleDesc = SafeHiddenTroubleDesc.Text;
            _EM.IsSafeEnough = CheckBox1.Checked;
            _EM.RepairingDesc = RepairingDesc.Text;
            if (BaoXiuDate.Text == "")
                _EM.BaoXiuDate = null;
            else
                _EM.BaoXiuDate = DateTime.Parse(BaoXiuDate.Text);
            if (StartRepairDate.Text == "")
                _EM.StartRepairDate = null;
            else
                _EM.StartRepairDate = DateTime.Parse(StartRepairDate.Text);
            if (EndRepairDate.Text == "")
                _EM.EndRepairDate = null;
            else
                _EM.EndRepairDate = DateTime.Parse(EndRepairDate.Text);
            _EM.RepairedDesc = RepairedDesc.Text;
            int iState = -1;
            if (CheckBox3.Checked)
                iState = 0;
            if (CheckBox4.Checked)
                iState = 1;
            if (CheckBox5.Checked)
                iState = 2;
            _EM.RepairUserState = iState;
            _EM.RepairUserZPTName = RepairUserZPTName.Text;
            _EM.RepairUserZPTDate = RepairUserZPTDate.Text;
            _EM.RepairUserName = RepairUserName.Text;
            new Catering_Rules.EMaintenance().Add(_EM);
            ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "onekey", "alert('保存成功！');;window.setTimeout('window.close()',1000);", true);
        }  
    }
}